$.extend({
	/**
	 * 加载数据列表及编辑删除
	 * names		获取数据的一系列参数。其中name代表值的名字，isTd代表是否显示在table上，size代表弹出窗口的input大小
	 * input代表编辑或添加窗口的input样式及名字，type代表主要类型，如main则是id，time会转化时间格式等
	 * parms		页面参数
	 * urls			异步请求参数
	 * config		配置参数，如（ueditor,webuploader等插件 或 下载按钮）
	 * isLoadPls	加载页数列表参数
	 */
	loadTbl:function(names,parms,urls,config,isLoadPls){
		unbind();
		var parmData = {
			pageNum:parms.pageNum,
			pageSize:parms.pageSize
		};
		if(parms.zTree != null){
			parmData[parms.zTree.name] = parms.zTree.value;
		}
		$.ajax({
			url:urls.load,
			type:"POST",
			data:parmData,
			dataType:"json",
			success:function(data){
				if(data.res == 1){
					var tbText = "";
					var results = data.obj.results;
					for( var i = 0; i < results.length; i++){
						if(names != null && names.length > 0){
							tbText += '<tr>';
							for(var j = 0; j < names.length; j++){
								if(names[j].name != null && (names[j].isTd == null || names[j].isTd == true)){
									if(typeof(names[j].name) == 'function'){
										tbText += names[j].name(i,results[i],false);
									}else{
										if(names[j].type != null) tbText += $.loadStyle(names[j].type, null, results[i][names[j].name], names[j].name, null, "td");
										else tbText += '<td>' + results[i][names[j].name] + '</td>';
									}
								}
							}
							tbText += '<td>';
							if(config != null && config.listbtns != null){
								tbText += config.listbtns();
							}else{
								tbText += '<div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">';
								tbText += '	<a class="single-edit green" href="#modal-table" data-toggle="modal"><i class="icon-pencil bigger-130"></i></a>';
								tbText += '	<a class="single-delete red"><i class="icon-trash bigger-130"></i></a>';
								if(config != null && config.download){
									tbText += '	<a class="single-download green"><i class="icon-download bigger-130"></i></a>';
								}
								tbText += '</div><div class="visible-xs visible-sm hidden-md hidden-lg"><div class="inline position-relative">';
								tbText += '	<button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown"><i class="icon-caret-down icon-only bigger-120"></i></button>';
								tbText += '	<ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">';
								tbText += '		<li><a href="#modal-table" data-toggle="modal" class="single-edit tooltip-success" data-rel="tooltip" title="Edit"><span class="green"><i class="icon-edit bigger-120"></i></span></a></li>';
								tbText += '		<li><a class="single-delete tooltip-error" data-rel="tooltip" title="Delete"><span class="red"><i class="icon-trash bigger-120"></i></span></a></li>';
								tbText += '	</ul></div></div>';
							}
							tbText += '</td></tr>';
						}
					}
					$("#modal-close-btn").click(function(){
						$(".uploader-container").find('input[for-format=empty-uploader]').click();
					});
					$("#sample-table-1 > tbody").empty();
					$("#sample-table-1 > tbody").append(tbText);
					if(config != null && config.download){
						$(".single-download").click(function(){
							var t = $(this).parent().parent().parent()[0].firstChild;
							var cid = $(t).find(":input").val();
							window.open(urls.download + "?id=" + cid);
//							$.post(urls.download,{id:cid},function(data){
//								if(!data.match("^\{(.+:.+,*){1,}\}$")){
//								}else{
//									data = eval("(" + data + ")");
//									alert(data.resMsg);
//								}
//							});
						});
					}
					$(".single-edit").click(function(){
						formInit();
						var t = $(this).parent().parent().parent()[0].firstChild;
						var cid = $(t).find(":input").val();
						var values = "";
						$.ajax({
							url:urls.detail,
							type:"POST",
							data:{
								id:cid
							},
							dataType:"json",
							success:function(data){
								if(data.res == 1){
									values = data.obj;
									var model = '';
									var sizes = [4,8,8];
									if(names != null && names.length > 0){
										for(var i = 0; i < names.length; i++){
											var placeholder = '';
											if(names[i].isEdit != null && !names[i].isEdit) continue;
											if(names[i].size != null){
												if(names[i].size == 'L') sizes = [2,10,11];
												else if(names[i].size == 'M') sizes = [3,9,10];
											}
											if(typeof(names[i].input) == 'function'){
												placeholder = names[i].input(null,false,true);
												model += '<div class="space-4"></div><div class="form-group"><label class="control-label col-xs-12 col-sm-'+sizes[0]+' no-padding-right">'+placeholder+'</label>';
												model += names[i].input(values,false,false);
											}else{
												var name = '';
												if(typeof(names[i].name) == 'function'){
													name = names[i].name(null,null,true);
												}else name = names[i].name;
												if(i == 0){
													var b = '<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span id="modal-close-btn" class="white">&times;</span></button>';
													$(".modal-header > .table-header").html(b + names[i].input + '编辑');
													model += '<input type="hidden" name="'+name+'" value="' + values[name] + '">';
													if(config != null && config.uploader == true){
														$("input[for-format='reload-uploader']").attr("id",values[name]);
													}
												}else{
													if(names[i].input != null){
														placeholder = names[i].input;
														model += '<div class="space-4"></div><div class="form-group"><label class="col-sm-'+sizes[0]+' control-label no-padding-right" for="form-field-1"> ' + placeholder + ' </label>';
														if(names[i].type != null) model += $.loadStyle(names[i].type, sizes, values, name, placeholder, "edit");
														else{
															model += '<div class="col-sm-'+sizes[1]+'"><input type="text" id="form-field-1" placeholder="' + names[i].input + '" name="'+name+'" value="' + values[name] + '" class="col-xs-10 col-sm-'+sizes[2]+'" /></div></div>';
														}
													}else{
														if(names[i].type != null) model += $.loadStyle(names[i].type, sizes, values, name, null, "edit");
													}
												}
											}
										}
									}
									$("#modal-table-container").append(model);
									model = '<div class="center">';
									if(config != null && config.formbtns != null){
										model += config.formbtns(values);
									}else{
										model += '<button type="button" class="single-edit-sub btn btn-sm btn-success">Submit<i class="icon-arrow-right icon-on-right bigger-110"></i></button>';
									}
									model += '</div>';
									$("#modal-table-btn").append(model);
									$('.input-mask-phone').mask('99999999999');
									$("#modal-table-container").find("input[for-type=combox-select]").each(function(i,_this){
										var to = $(_this).attr("url");
										var data_v = $(_this).attr("data-v");
										var data_t = $(_this).attr("data-t");
										var name = $(_this).attr("name");
										$.ajax({
											url:to,
											type:"POST",
											dataType:"json",
											success:function(data){
												if(data.res == 1){
													var vals = data.obj;
													$(_this).after('<select class="col-xs-10 col-sm-'+sizes[2]+'" id="form-field-select-1"></select>');
													if(vals != null && vals.length > 0){
														var ops = '<option selected>--请选择--</option>';
														for(var i = 0; i < vals.length; i++){
															var selected = "";
															if(vals[i][data_v] == values[name]) selected = "selected";
															ops += '<option value="' + vals[i][data_v] + '" ' + selected + '>'+vals[i][data_t]+'</option>';
														}
														$(_this).next().append(ops);
														$("#form-field-select-1").change(function(){
															var up_val = $(this).children("option:selected").val();
															$(_this).attr("value",up_val);
														});
													}
												}
											}
										});
									});
									if(config != null){
										if(config.ueditor){
											UE.getEditor('editor').setContent(values[name], false);
										}
										if(config.uploader){
											$("input[for-format='reload-uploader']").click();
										}
										if(config.callback != null && config.callback.forEdit != null){
											config.callback.forEdit(values,names,parms,urls,config,isLoadPls);
										}
									}
									$(".single-edit-sub").click(function(){
										if(config != null && config.ueditor == true){
											$("input[for-format='rich-text']").val(UE.getEditor('editor').getContent());
										}
										var jsonData = $.getForm(".form-horizontal");
										$.ajax({
											url:urls.edit,
											type:"POST",
											data:JSON.stringify(jsonData),
											contentType:"application/json;charset=utf-8",
											dataType:"json",
											success:function(data){
												if(data.res == 1){
													bootbox.dialog({
														message: "<span class='bigger-110'>" + data.resMsg + " </span>",
														buttons: 			
														{
															"click" :
															{
																"label" : "确定",
																"className" : "btn-sm btn-primary",
																"callback": function() {
																	$(".uploader-container").find('input[for-format=empty-uploader]').attr("removeView",true);
																	$(".uploader-container").find('input[for-format=empty-uploader]').click();
																	$("#modal-close-btn").click();
																	$.loadTbl(names,parms,urls,config,true);
																}
															}, 
														}
													});
												}
											}
										});
									});
								}
							}
						});
					});
					$(".single-add").click(function(){
						formInit();
						var sizes = [4,8,8];
						if(names != null && names.length > 0){
							var model = '';
							for(var i = 0; i < names.length; i++){
								if(names[i].isAdd != null && !names[i].isAdd){
									continue;
								}
								if(names[i].size != null){
									if(names[i].size == 'L') sizes = [2,10,11];
									else if(names[i].size == 'M') sizes = [3,9,10];
								}
								var placeholder = '';
								if(typeof(names[i].input) == 'function'){
									placeholder = names[i].input(null,false,true);
									model += '<div class="space-4"></div><div class="form-group"><label class="control-label col-xs-12 col-sm-'+sizes[0]+' no-padding-right">'+placeholder+'</label>';
									model += names[i].input(null,true,false);
								}else{
									var name = '';
									if(typeof(names[i].name) == 'function'){
										name = names[i].name(null,null,true);
									}else name = names[i].name;
									if(i == 0){
										var b = '<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span id="modal-close-btn" class="white">&times;</span></button>';
										$(".modal-header > .table-header").html(b + '添加' + names[i].input);
									}else{
										if(names[i].input != null){
											placeholder = names[i].input;
											model += '<div class="space-4"></div><div class="form-group"><label class="col-sm-'+sizes[0]+' control-label no-padding-right" for="form-field-1"> ' + placeholder + ' </label>';
											if(names[i].type != null)model += $.loadStyle(names[i].type, sizes, null, names[i].name, placeholder, "add");
											else
												model += '<div class="col-sm-'+sizes[1]+'"><input type="text" id="form-field-1" placeholder="' + names[i].input + '" name="'+name+'" value="" class="col-xs-10 col-sm-'+sizes[2]+'" /></div></div>';
										}else{
											if(names[i].type != null) model += $.loadStyle(names[i].type, sizes, null, names[i].name, null, "add");
										}
									}
								}
							}
						}
						$("#modal-table-container").append(model);
						model = '<div class="center"><button type="button" class="single-add-sub btn btn-sm btn-success">Submit';
						model += '<i class="icon-arrow-right icon-on-right bigger-110"></i></button>&nbsp; &nbsp; &nbsp;';
						model += '<button class="btn btn-sm" type="reset"><i class="icon-undo bigger-110"></i>Reset</button></div>';
						$("#modal-table-btn").append(model);
						$('.input-mask-phone').mask('99999999999');
						$("#modal-table-container").find("input[for-type=combox-select]").each(function(i,_this){
							var to = $(_this).attr("url");
							var data_v = $(_this).attr("data-v");
							var data_t = $(_this).attr("data-t");
							$.ajax({
								url:to,
								type:"POST",
								dataType:"json",
								success:function(data){
									if(data.res == 1){
										var vals = data.obj;
										$(_this).after('<select class="col-xs-10 col-sm-'+sizes[2]+'" id="form-field-select-1"></select>');
										if(vals != null && vals.length > 0){
											var ops = '<option selected>--请选择--</option>';
											for(var i = 0; i < vals.length; i++){
												ops += '<option value="' + vals[i][data_v] + '">'+vals[i][data_t]+'</option>';
											}
											$(_this).next().append(ops);
											$("#form-field-select-1").change(function(){
												var up_val = $(this).children("option:selected").val();
												$(_this).attr("value",up_val);
											});
										}
									}
								}
							});
						});
						if(config != null){
							if(config.uploader){
								$('.queueList > .filelist').find("li").remove();
							}
							if(config.datepicker){
								$('.date-picker').datetimepicker({
							        weekStart: 1,
							        todayBtn:  1,
									autoclose: 1,
									todayHighlight: 1,
									startView: 2,
									forceParse: 0,
							        showMeridian: 1
							    });
							}
						}
						$(".single-add-sub").click(function(){
							if(config != null && config.ueditor == true){
								$("input[for-format='rich-text']").val(UE.getEditor('editor').getContent());
							}
							var jsonData = $.getForm(".form-horizontal");
							$.ajax({
								url:urls.add,
								type:"POST",
								data:JSON.stringify(jsonData),
								dataType:"json",
								contentType:"application/json;charset=utf-8",
								success:function(data){
									if(data.res == 1){
										bootbox.dialog({
											message: "<span class='bigger-110'>" + data.resMsg + " </span>",
											buttons: 			
											{
												"click" :
												{
													"label" : "确定",
													"className" : "btn-sm btn-primary",
													"callback": function() {
														$(".uploader-container").find('input[for-format=empty-uploader]').attr("removeView",true);
														$(".uploader-container").find('input[for-format=empty-uploader]').click();
														$("#modal-close-btn").click();
														$.loadTbl(names,parms,urls,config,true);
													}
												}, 
											}
										});
									}
								}
							});
						});
					});
					$(".single-delete").click(function(){
						var t = $(this).parent().parent().parent()[0].firstChild;
						var name = $(t).next().text();
					 	bootbox.dialog({
							message: "<span class='bigger-110'>确认是否删除   " + name + " </span>",
							buttons: 			
							{
								"danger" :
								{
									"label" : "确认",
									"className" : "btn-sm btn-danger",
									"callback": function() {
										var del_id = $(t).find(":input").val();
										$.ajax({
											url:urls.del,
											type:"GET",
											data:{
												id:del_id,
											},
											dataType:"json",
											success:function(data){
												if(data.res == 1){
													$.loadTbl(names,parms,urls,config,true);
												}
											}
										});
									}
								}, 
								"click" :
								{
									"label" : "取消",
									"className" : "btn-sm btn-primary",
									"callback": function() {
										//Example.show("Primary button");
									}
								}, 
							}
						});
					});
					$(".batch-del").click(function(){
						var msg = "确认是否删除选中项";
						if(!$("#sample-table-1 tbody").children("tr").find("input[type=checkbox]").is(":checked")){
							msg = "未选择删除项";
						}
						bootbox.dialog({
							message: "<span class='bigger-110'> " + msg + " </span>",
							buttons: 			
							{
								"danger" :
								{
									"label" : "确认",
									"className" : "btn-sm btn-danger",
									"callback": function() {
										if(msg == "未选择删除项") return;
										var data = [];
										$("#sample-table-1 tbody").find("input[type=checkbox]").each(function(index,_this){
											if($(_this).is(":checked")){
												data.push({id:$(_this).attr("value")});
											}
										});
										$.ajax({
											url:urls.delBatch,
											type:"POST",
											data:JSON.stringify(data),
											dataType:"json",
											contentType:"application/json; charset=utf-8",
											success:function(data){
												if(data.res == 1){
													if($('table th input:checkbox').is(":checked")){
														$('table th input:checkbox').click();
													}
													$.loadTbl(names,parms,urls,config,true);
												}
											}
										});
									}
								}, 
								"click" :
								{
									"label" : "取消",
									"className" : "btn-sm btn-primary",
									"callback": function() {
										//Example.show("Primary button");
									}
								}, 
							}
						});
					});
					if(isLoadPls){
						$(".pagination").empty();
						parms.pageNum = data.obj.pageNum;
						parms.pageSize = data.obj.pageSize;
						$.loadPls(names,parms,urls,config,data.obj.totalPage);
					}
					
				}
			}
		});
		//解除click绑定事件
		function unbind(){
			$(".batch-del").unbind();
			$(".single-add").unbind();
		}
		function formInit(){
			$("#modal-table").css("display","block");
			$(".uploader-container").find("#dndArea").removeClass("element-invisible");
			$(".uploader-container").find(".statusBar").addClass("element-invisible");
			$(".uploader-container").find(".filelist").css("display","none");
			$(".uploader-container").find('input[for-format=empty-uploader]').attr("removeView",false);
			$(".uploader-container").find('input[for-format=empty-uploader]').click();
			$("#modal-table").css("display","none");
			$("#modal-table-btn").empty();
			$("#modal-table-container").empty();
			if(config != null){
				if(config.ueditor){
					UE.getEditor('editor').setContent("", false);
				}
			}
		}
	},
	getForm:function(_form){
		var multiData = [];
		var obs = {};
		var obj = {};
		$(_form).find(":input").each(function(index,_this){
			if($(_this).is("[type='file']"))return;
			var name = $(_this).attr("name");
			var val = $(_this).val();
			if($(_this).is("[type='checkbox']")){
				val = $(_this).is(":checked");
				if(val) val = 1;
				else val = 2;
			}
			if(name != null && name != "" && val != null && val != ""){
				if($(_this).is("[for-multi]")){
					if(name in obs){
						multiData.push(obs);
						obs = {};
					}
					obs[name] = val;
				}else obj[name] = val;
			}
			
		});
		multiData.push(obs);
		var a = {multi:[],'obj':[]};
		a.multi = multiData;
		a.obj.push(obj);
		return a;
	},
	loadPls:function(names,parms,urls,config,totalPage){
		if(totalPage > 1){
			var text = "";
			var symbol1 = false;
			var symbol2 = false;
			var disabled = "";
			if(parms.pageNum == 1) disabled = 'disabled';
			text += '<li class="turn ' + disabled + '"><a value="1">第一页</a></li>';
			text += '<li class="prev ' + disabled + '" style="font-size:1.8rem;"><a><i class="icon-double-angle-left"></i></a></li>';
			for( var i = 1; i <= totalPage; i++){
				if(totalPage >= 7 && parms.pageNum > 1 && i < parms.pageNum && i < totalPage - 5){
					if(symbol2)continue;
					symbol2 = true;
					text += '<li><a>...</a></li>';
				}else if(parms.pageNum == i){
					text += '<li class="active"><a value="' + i + '">' + i + '</a></li>';
				}else if(totalPage >= 7 && parms.pageNum < (i - 2) && i < totalPage - 2){
					if(symbol1)continue;
					symbol1 = true;
					text += '<li><a>...</a></li>';
				}else text += '<li class="turn"><a value="' + i + '">' + i + '</a></li>';
			}
			disabled = '';
			if(parms.pageNum == totalPage) disabled = 'disabled';
			text += '<li class="next ' + disabled + '" style="font-size:1.8rem;"><a><i class="icon-double-angle-right"></i></a></li>';
			text += '<li class="turn ' + disabled + '"><a value="' + totalPage + '">最后页</a></li>';
			$(".pagination").append(text);
			
			$(".prev").click(function(){
				if(parms.pageNum > 1){
					parms.pageNum -= 1;
					$.loadTbl(names,parms,urls,config,true);
				}
			});
			$(".next").click(function(){
				if(parms.pageNum < totalPage){
					parms.pageNum += 1;
					$.loadTbl(names,parms,urls,config,true);
				}
			});
			$(".turn").click(function(){
				var i = $(this).children().attr("value");
				if(i <= totalPage && i > 0){
					parms.pageNum = i;
					$.loadTbl(names,parms,urls,config,true);
				}
			});
		}
	},
	loadCombox:function(){

	},
	loadStyle:function(type, size, value, name, placeholder, usage){
		if(type != null && type != ""){
			switch(type){
			case 'main':
				return '<td class="center"><label><input type="checkbox" class="ace" value="' + value + '" /><span class="lbl"></span></label></td>';
			case 'time&hidden':
				if(usage == "td"){
					value = $.loadTime.castToDateTime(value);
					return '<td>'+value+'</td>';
				}else if(usage == "edit"){
					return '<input type="hidden" name="' + name + '" value="' + value[name] + '">';
				}else if(usage == "add"){
					return '<input type="hidden" name="' + name + '">';
				}
			case 'hidden':
				if(usage == "td"){
					return '<td>'+value+'</td>';
				}else if(usage == "edit"){
					return '<input type="hidden" name="' + name + '" value="' + value[name] + '">';
				}else if(usage == "add"){
					return '<input type="hidden" name="' + name + '">';
				}
			case 'disabled':
				if(usage == "td"){
					return '<td>'+value+'</td>';
				}else if(usage == "edit"){
					return '<div class="col-sm-'+size[1]+'"><input type="text" id="form-field-1" name="'+name+'" value="' + value[name] + '" class="col-xs-10 col-sm-'+size[2]+'" disabled/></div></div>';
				}else if(usage == "add"){
					return '<div class="col-sm-'+size[1]+'"><input type="text" id="form-field-1" placeholder="' + placeholder + '" name="'+name+'" class="col-xs-10 col-sm-'+size[2]+'" /></div></div>';
				}
			}
		}
	},
	loadConfig:function(config){
		if(config != null && config.length > 0){
			if(config.ueditor){
				
			}
		}
	},
	loadTime:{
		    /**
		     * 获取当前时间毫秒数
		     */
		    getCurrentMsTime : function() {
		        var myDate = new Date();
		        return myDate.getTime();
		    },
		    /**
		     * 毫秒转时间格式
		     */
		    castToDateTime : function(time) {
		        var myDate = new Date(time);
		        return this.formatterDateTime(myDate);
		    },
		    /**
		     * 时间格式转毫秒
		     */
		    dateToLongMsTime : function(date) {
		        var myDate = new Date(date);
		        return myDate.getTime();
		    },
		    /**
		     * 格式化日期（不含时间）
		     */
		    formatterDate : function(date) {
		        var datetime = date.getFullYear()
		                + "-"// "年"
		                + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
		                        + (date.getMonth() + 1))
		                + "-"// "月"
		                + (date.getDate() < 10 ? "0" + date.getDate() : date
		                        .getDate());
		        return datetime;
		    },
		    /**
		     * 格式化日期（含时间"00:00:00"）
		     */
		    formatterDate2 : function(date) {
		        var datetime = date.getFullYear()
		                + "-"// "年"
		                + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
		                        + (date.getMonth() + 1))
		                + "-"// "月"
		                + (date.getDate() < 10 ? "0" + date.getDate() : date
		                        .getDate()) + " " + "00:00:00";
		        return datetime;
		    },
		    /**
		     * 格式化去日期（含时间）
		     */
		    formatterDateTime : function(date) {
		        var datetime = date.getFullYear()
		                + "-"// "年"
		                + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
		                        + (date.getMonth() + 1))
		                + "-"// "月"
		                + (date.getDate() < 10 ? "0" + date.getDate() : date
		                        .getDate())
		                + " "
		                + (date.getHours() < 10 ? "0" + date.getHours() : date
		                        .getHours())
		                + ":"
		                + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
		                        .getMinutes())
		                + ":"
		                + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date
		                        .getSeconds());
		        return datetime;
		    },
		    /**
		     * 时间比较{结束时间大于开始时间}
		     */
		    compareDateEndTimeGTStartTime : function(startTime, endTime) {
		        return ((new Date(endTime.replace(/-/g, "/"))) > (new Date(
		                startTime.replace(/-/g, "/"))));
		    },
		    /**
		     * 验证开始时间合理性{开始时间不能小于当前时间{X}个月}
		     */
		    compareRightStartTime : function(month, startTime) {
		        var now = formatterDayAndTime(new Date());
		        var sms = new Date(startTime.replace(/-/g, "/"));
		        var ems = new Date(now.replace(/-/g, "/"));
		        var tDayms = month * 30 * 24 * 60 * 60 * 1000;
		        var dvalue = ems - sms;
		        if (dvalue > tDayms) {
		            return false;
		        }
		        return true;
		    },
		    /**
		     * 验证开始时间合理性{结束时间不能小于当前时间{X}个月}
		     */
		    compareRightEndTime : function(month, endTime) {
		        var now = formatterDayAndTime(new Date());
		        var sms = new Date(now.replace(/-/g, "/"));
		        var ems = new Date(endTime.replace(/-/g, "/"));
		        var tDayms = month * 30 * 24 * 60 * 60 * 1000;
		        var dvalue = sms - ems;
		        if (dvalue > tDayms) {
		            return false;
		        }
		        return true;
		    },
		    /**
		     * 验证开始时间合理性{结束时间与开始时间的间隔不能大于{X}个月}
		     */
		    compareEndTimeGTStartTime : function(month, startTime, endTime) {
		        var sms = new Date(startTime.replace(/-/g, "/"));
		        var ems = new Date(endTime.replace(/-/g, "/"));
		        var tDayms = month * 30 * 24 * 60 * 60 * 1000;
		        var dvalue = ems - sms;
		        if (dvalue > tDayms) {
		            return false;
		        }
		        return true;
		    },
		    /**
		     * 获取最近几天[开始时间和结束时间值,时间往前推算]
		     */
		    getRecentDaysDateTime : function(day) {
		        var daymsTime = day * 24 * 60 * 60 * 1000;
		        var yesterDatsmsTime = this.getCurrentMsTime() - daymsTime;
		        var startTime = this.longMsTimeConvertToDateTime(yesterDatsmsTime);
		        var pastDate = this.formatterDate2(new Date(startTime));
		        var nowDate = this.formatterDate2(new Date());
		        var obj = {
		            startTime : pastDate,
		            endTime : nowDate
		        };
		        return obj;
		    },
		    /**
		     * 获取今天[开始时间和结束时间值]
		     */
		    getTodayDateTime : function() {
		        var daymsTime = 24 * 60 * 60 * 1000;
		        var tomorrowDatsmsTime = this.getCurrentMsTime() + daymsTime;
		        var currentTime = this.longMsTimeConvertToDateTime(this.getCurrentMsTime());
		        var termorrowTime = this.longMsTimeConvertToDateTime(tomorrowDatsmsTime);
		        var nowDate = this.formatterDate2(new Date(currentTime));
		        var tomorrowDate = this.formatterDate2(new Date(termorrowTime));
		        var obj = {
		            startTime : nowDate,
		            endTime : tomorrowDate
		        };
		        return obj;
		    },
		    /**
		     * 获取明天[开始时间和结束时间值]
		     */
		    getTomorrowDateTime : function() {
		        var daymsTime = 24 * 60 * 60 * 1000;
		        var tomorrowDatsmsTime = this.getCurrentMsTime() + daymsTime;
		        var termorrowTime = this.longMsTimeConvertToDateTime(tomorrowDatsmsTime);
		        var theDayAfterTomorrowDatsmsTime = this.getCurrentMsTime()+ (2 * daymsTime);
		        var theDayAfterTomorrowTime = this.longMsTimeConvertToDateTime(theDayAfterTomorrowDatsmsTime);
		        var pastDate = this.formatterDate2(new Date(termorrowTime));
		        var nowDate = this.formatterDate2(new Date(theDayAfterTomorrowTime));
		        var obj = {
		            startTime : pastDate,
		            endTime : nowDate
		        };
		        return obj;
		    }
	},
	loadLogin:function(urls){
		$(".input-login-name").attr("title","不能为空，账号:admin");
		$(".input-login-pwd").attr("title","不能为空，密码:123456");
		$(".btn-login").click(function(){
			var datum = getForm(".form-login");
			var r = checkFormData(null, datum);
			if(r && urls!=null){
				$.ajax({
					url:urls.login,
					data:datum,
					success:function(result){
						result = eval("(" + result + ")");
						if(result.res == 1){
							$(location).attr('href', 'bg/index');
						}else{
							$("#login-box h4").attr("data-original-title",result.resMsg);
							$("#login-box h4").trigger("mouseenter");
						}
					}
				});
			}
		});
		$('[data-rel=tooltip]').tooltip();
		function checkFormData(_form, data){
			if(null != _form && null == data){
				data = getForm(_form);
			}
			var r = true;
			for(var name in data){
				if(data[name] == undefined){
					r = false;
					var input = $("input[name="+name+"]").parent();
					$(input).trigger('mouseenter');
				}
			}
			return r;
		}
		function getForm(_form){
			var obj = {};
			$(_form).find(":input").each(function(index,_this){
				var name = $(_this).attr("name");
				var val = $(_this).val();
				if(name != null && name != "" && val != null && val != ""){
					obj[name] = val;
				}else{
					if($(this).attr("extra") == "input-important"){
						obj[name] = undefined;
					}
				}
			});
			return obj;
		}
	}
});



